<?php
include "header.php";
include "footer.php";
require_once './libs/Page.class.php';

$sql_cnt = "SELECT id FROM wish";
$result = $conn->query($sql_cnt);
$total_cnt = $result->num_rows;
$listRows = 5;
$total_pages = ceil($total_cnt/$listRows);

 $Page = new Page($total_cnt,$listRows);

$page = empty($_GET['p']) ? 1 : $_GET['p'];
$page = ($page < 1) ? 1 : $page;
$page = ($page > $total_pages) ? $total_pages:$page;

$sql = "SELECT * FROM  wish LIMIT " . ($page-1)*5 . ",5";

$result = $conn->query($sql);


$arrlist = array();

if ($result->num_rows > 0) {  
    // 输出每行数据
    while($row = $result->fetch_assoc()) {
        array_push($arrlist, $row);        
    }
} else {
    echo "0 results";
}
$conn->close(); 
?>

<div id="right">
	
<table border="1">
<tr>
<td>序号</td>
<td>留言者</td>
<td>留言内容</td>
<td>留言时间</td>
<td>操作</td>
</tr>
<?php foreach($arrlist as $vo){ ?>
<tr>
<td><?php echo $vo['id'];?></td>
<td><?php echo $vo['username'];?></td>
<td><?php echo $vo['content'];?></td>
<td><?php echo $vo['time_at'];?></td>
<td><span><a>修改</a></span> | <span><a href="delete.php?id=<?php echo $vo['id'];?>" onclick="return delcfm()">删除</a></span></td>
</tr>
<?php } ?>
</table>
 
    
    <script>
        function delcfm(){
            if (!confirm("确定要删除么？")) {
                window.event.returnVaule = false;
            }
                
        }
    </script>
    <div class="Pagination">
        <?php 
        echo $Page->showpage();
       
        ?>
    </div>
    
   
    
</div>

